package com.stadium.web.controller;

import com.fastsite.common.api.ApiResult;
import com.fastsite.common.api.ApiSecured;
import com.github.xiaoymin.knife4j.spring.util.ByteUtils;
import com.stadium.web.service.FileService;
import com.stadium.web.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;

/**
 * 文件管理Controller
 * 
 * @author ruoyi
 * @date 2020-02-17
 */
@Api(tags = "文件上传")
@Validated
@RestController
@RequestMapping("/file")
public class FileController
{

    @Autowired
    private FileService fileService;

    /**
     * 单文件上传
     */
    @ApiOperation("文件上传服务类")
    @PostMapping({"/oneUpload"})
    public ApiResult oneUpload(HttpServletRequest request,@ApiParam(value = "文件流")@ RequestPart("file") MultipartFile file,
                               @ApiParam(value = "文件名称")String filename){
        String fileUrl = fileService.uploadFile(request,file,filename);
        return ApiResult.ok(fileUrl,"上传成功！");
    }
}
